# Faster KBand Mapping: see README.md.

def map_place(x, y, n) -> int:
    return x * n + y

def insideBand(x, y, band, n) -> bool:
    if x < 0 or y < 0 or x >= n or y >= n: return False
    return abs(x - y) <= band

def Mapping(n, p, k, l = True) -> int:
    i = p // n
    j = p % n
    if k <= (n - 1) // 2:
        if i <= k: 
            if l: print("A", end = ' ')
            return i * k + (i + 1) * i // 2 + j + 1
        elif k + 1 <= i < n - 1 - k:
            if l: print("B", end = ' ')
            return k * (k + 1) + (k + 1) * (k + 2) // 2 + (i - k - 1) * (2 * k + 1) + k + 1 + j - i
        else:
            if l: print("C", end = ' ')
            return (k + 1) * k + (k + 1) * (k + 2) // 2 + (n - 2 * k - 2) * (2 * k + 1) + \
                2 * k * ( i - n + 1 + k ) - ( i - n + k - 1 ) *( i - n + k ) // 2 + 1 + k + 1 + j - i
    else:
        if i <= n - k - 1:
            if l: print("D", end = ' ')
            return i * k + (i + 1) * i // 2 + j + 1
        elif n - k - 1 < i <= k :
            if l: print("E", end = ' ')
            # print((k + 1 + n) * (n - k) // 2, n * (i - n + k), end = ' ') 
            return (k + 1 + n) * (n - k) // 2 + n * (i - n + k) + j + 1
        else:
            if l: 
                print("F", end = ' ')
                '''
                print((k + 1 + n) * (n - k) // 2 + n * (k + 1 - (n - k))) # Before the full blocks
                print((n - 1 + n + k - i + 1), (i - 1 - k)) # not full blocks, including this line
                print(j - i + k + 1)
                '''
            return ((k + 1 + n) * (n - k) // 2 + n * (k + 1 - (n - k)) + (n - 1 + n + k - i + 1) * (i - 1 - k) // 2 + j - i + k + 1)
            
            # return k * (n - k) + (n - k) * (n - k + 1) // 2 + n * (i - n + k) - (i - n + k) * (i - n + k + 1) // 2 + j - i + n - k



if __name__ == '__main__':
    n = int(input())
    band = int(input())
    band = min(n, band)
    ans = []
    for i in range(n):
        for j in range(-band, band + 1):
        #for j in range(n):
            if (insideBand(i, j + i, band, n) == False): continue
            print(i, j + i, end = ' ')
            print(Mapping(n, map_place(i, j + i, n), band))
            ans.append(Mapping(n, map_place(i, j + i, n), band, False))
    
    ans.sort()
    for i in range(len(ans) - 1):
        if(ans[i] + 1 != ans[i + 1]):
            print("Wrong")
        
    # raw method
    allline_low = [0 for i in range(n)]
    for i in range(n):
        allline_low[i] = 2 * band + 1 - max(band - i, 0) - max(band + i - n + 1, 0)
    #print(allline_low)
    # Calculating the pre-sum of it
    for i in range(1, n):
        allline_low[i] += allline_low[i - 1]

    print(allline_low[-1], len(ans) == allline_low[-1])